package cn.stylefeng.guns.modular.cb.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cb.entity.CbPosition;
import cn.stylefeng.guns.modular.cb.mapper.CbPositionMapper;
import cn.stylefeng.guns.modular.cb.model.params.CbPositionParam;
import cn.stylefeng.guns.modular.cb.model.result.CbPositionResult;
import  cn.stylefeng.guns.modular.cb.service.CbPositionService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  招聘职位 服务实现类
 * </p>
 *
 * @author wj
 * @since 2021-01-05
 */
@Service
public class CbPositionServiceImpl extends ServiceImpl<CbPositionMapper, CbPosition> implements CbPositionService {

    @Override
    public void add(CbPositionParam param){
        CbPosition entity = getEntity(param);
        entity.setResumeCount(0);
        this.save(entity);
    }

    @Override
    public void delete(CbPositionParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(CbPositionParam param){
        CbPosition oldEntity = getOldEntity(param);
        CbPosition newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CbPositionResult findBySpec(CbPositionParam param){
        return null;
    }

    @Override
    public List<CbPositionResult> findListBySpec(CbPositionParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(CbPositionParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpec2(CbPositionParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList2(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<CbPositionResult> customList2(CbPositionParam param) {
        return this.baseMapper.customList2(param);
    }

    @Override
    public CbPositionResult getCbPositionInfo(Long id) {
        return this.baseMapper.getCbPositionInfo(id);
    }

    @Override
    public CbPositionResult getCbPositionDetail(Long id) {
        return this.baseMapper.getCbPositionDetail(id);
    }

    @Override
    public List<CbPositionResult> positionByLimit2(Long companyId) {
        return this.baseMapper.positionByLimit2(companyId);
    }


    /**
     * 本企业招聘职位
     * @param paramCondition
     * @return
     */
    @Override
    public List<CbPositionResult> positionByNameList(CbPositionParam paramCondition) {
        return this.baseMapper.positionByNameList(paramCondition);
    }

    /**
     * 每日新增职位统计
     * @param startDate
     * @param countArr
     * @return
     */
    @Override
    public List<Map<String, Object>> queryDateCount(String startDate, String[] countArr) {
        return this.baseMapper.queryDateCount(startDate, countArr);
    }

    /**
     * 学长发布的职位
     * @param companyId
     * @return
     */
    @Override
    public List<CbPositionResult> listPositionByStaff(String companyId) {
        return this.baseMapper.listPositionByStaff(companyId);
    }

    private Serializable getKey(CbPositionParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private CbPosition getOldEntity(CbPositionParam param) {
        return this.getById(getKey(param));
    }

    private CbPosition getEntity(CbPositionParam param) {
        CbPosition entity = new CbPosition();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
}
